package core

import "openzbox.com/log"

var gateway *Mbox

/*自检程序*/
func DoSelfTest() {

	//初始化盒子配置
	gateway = &Mbox{}
	err := InitBox(gateway)
	if err != nil {
		log.Fatalf("InitBox fault. %s", err)
	}
	//log.Infof("mbox config:%v", mbox)
	log.Infof("initialize openzbox %s...", gateway.Name)
	//闪烁活动指示LED，1000毫秒间隔
	gateway.OpenFaultLED(1000)
	//开启故障指示灯 500 毫秒间隔
	gateway.OpenActiveLED(500)

	//同步系统时间
	err = gateway.SyncRtcTimeFromInternet()
	if err == nil {
		log.Info("Sync datetime from internet NTP success.")
	} else {
		log.Infof("Sync datetime from internet NTP fault. %s", err)
	}
	//2.开启看门狗
	/*
		注意：看起看门狗之前，需要先停掉系统默认配置的看门狗程序
		vi /etc/init.d/rcS
		将下列行注释掉
		/sbin/wdt &
		在程序内开启看门狗后，如果将应用程序进程杀掉后，8秒左右系统将会重启。
	*/
	if 1 == 1 {
		err = gateway.WDTKeepLive()
		log.Info("Start Watchdog keep live...")
		if err != nil {
			log.Error("Watch dog rrr:", err)
		}
	}
	//log.Infof("the system will cold restart in 5 seconds.")
	//gateway.Reboot()
	gateway.PowerReboot()

	//广播本机信息
	//gateway.Iamhere()

	gateway.CloseFaultLED()
	gateway.CloseActiveLED()
}
